set(MOC_HEADERS
    ../include/toonz/fullcolorpalette.h
    ../include/toonz/movierenderer.h
    ../include/toonz/multimediarenderer.h
    ../include/toonz/palettecontroller.h
    ../include/toonz/preferences.h
    ../include/toonz/scriptbinding.h
    ../include/toonz/scriptbinding_centerline_vectorizer.h
    ../include/toonz/scriptbinding_files.h
    ../include/toonz/scriptbinding_image.h
    ../include/toonz/scriptbinding_image_builder.h
    ../include/toonz/scriptbinding_level.h
    ../include/toonz/scriptbinding_outline_vectorizer.h
    ../include/toonz/scriptbinding_rasterizer.h
    ../include/toonz/scriptbinding_renderer.h
    ../include/toonz/scriptbinding_scene.h
    ../include/toonz/scriptbinding_toonz_raster_converter.h
    ../include/toonz/scriptengine.h
    ../include/toonz/stylemanager.h
    ../include/toonz/tcenterlinevectorizer.h
    ../include/toonz/tcolumnhandle.h
    ../include/toonz/tframehandle.h
    ../include/toonz/tfxhandle.h
    ../include/toonz/tobjecthandle.h
    ../include/toonz/tonionskinmaskhandle.h
    ../include/toonz/tpalettehandle.h
    ../include/toonz/tscenehandle.h
    ../include/toonz/txsheethandle.h
    ../include/toonz/txshlevel.h
    ../include/toonz/txshlevelhandle.h
    ../include/toonz/txshsimplelevel.h
    ../include/toonz/txshsoundcolumn.h
)

set(HEADERS
    ${MOC_HEADERS}
    autoadjust.h
    autopos.h
    cleanupcommon.h
    cleanuppalette.h
    imagebuilders.h
    skeletonlut.h
    tcenterlinevectP.h
    texturemanager.h
    xshhandlemanager.h
    sandor_fxs/BlurMatrix.h
    sandor_fxs/CIL.h
    sandor_fxs/CallCircle.h
    sandor_fxs/CallParam.h
    sandor_fxs/EraseContour.h
    sandor_fxs/InputParam.h
    sandor_fxs/Params.h
    sandor_fxs/Pattern.h
    sandor_fxs/PatternMapParam.h
    sandor_fxs/PatternPosition.h
    sandor_fxs/SDef.h
    sandor_fxs/SDirection.h
    sandor_fxs/SError.h
    sandor_fxs/STColSelPic.h
    sandor_fxs/STPic.h
    sandor_fxs/YOMBInputParam.h
    sandor_fxs/YOMBParam.h
    sandor_fxs/blend.h
    sandor_fxs/calligraph.h
    sandor_fxs/patternmap.h
    sandor_fxs/toonz4_6staff.h
    ../include/convert2tlv.h
    ../include/orientation.h
    ../include/toonz/Naa2TlvConverter.h
    ../include/toonz/autoclose.h
    ../include/toonz/boardsettings.h
    ../include/toonz/captureparameters.h
    ../include/toonz/childstack.h
    ../include/toonz/cleanupcolorstyles.h
    ../include/toonz/cleanupparameters.h
    ../include/toonz/columnfan.h
    ../include/toonz/controlpointobserver.h
    ../include/toonz/currentimage.h
    ../include/toonz/doubleparamcmd.h
    ../include/toonz/dpiscale.h
    ../include/toonz/fill.h
    ../include/toonz/fxcommand.h
    ../include/toonz/fxdag.h
    ../include/toonz/glrasterpainter.h
    ../include/toonz/hook.h
    ../include/toonz/ikengine.h
    ../include/toonz/ikjacobian.h
    ../include/toonz/iknode.h
    ../include/toonz/ikskeleton.h
    ../include/toonz/imagelocation.h
    ../include/toonz/imagemanager.h
    ../include/toonz/imagepainter.h
    ../include/toonz/imagestyles.h
    ../include/toonz/levelproperties.h
    ../include/toonz/levelset.h
    ../include/toonz/levelupdater.h
    ../include/toonz/logger.h
    ../include/toonz/mypaint.h
    ../include/toonz/mypaintbrushstyle.h
    ../include/toonz/mypainthelpers.hpp
    ../include/toonz/namebuilder.h
    ../include/toonz/observer.h
    ../include/toonz/onionskinmask.h
    ../include/toonz/palettecmd.h
    ../include/toonz/plasticdeformerfx.h
    ../include/toonz/rasterbrush.h
    ../include/toonz/rasterstrokegenerator.h
    ../include/toonz/scenefx.h
    ../include/toonz/sceneproperties.h
    ../include/toonz/sceneresources.h
    ../include/toonz/skeleton.h
    ../include/toonz/stage.h
    ../include/toonz/stage2.h
    ../include/toonz/stageobjectutil.h
    ../include/toonz/stageplayer.h
    ../include/toonz/stagevisitor.h
    ../include/toonz/studiopalette.h
    ../include/toonz/studiopalettecmd.h
    ../include/toonz/tapplication.h
    ../include/toonz/targetcolors.h
    ../include/toonz/tbinarizer.h
    ../include/toonz/tcamera.h
    ../include/toonz/tcleanupper.h
    ../include/toonz/tcolumnfx.h
    ../include/toonz/tcolumnfxset.h
    ../include/toonz/tdistort.h
    ../include/toonz/textureutils.h
    ../include/toonz/tlog.h
    ../include/toonz/toonzfolders.h
    ../include/toonz/toonzimageutils.h
    ../include/toonz/toonzscene.h
    ../include/toonz/tpinnedrangeset.h
    ../include/toonz/tproject.h
    ../include/toonz/trasterimageutils.h
    ../include/toonz/tstageobject.h
    ../include/toonz/tstageobjectcmd.h
    ../include/toonz/tstageobjectid.h
    ../include/toonz/tstageobjectkeyframe.h
    ../include/toonz/tstageobjectspline.h
    ../include/toonz/tstageobjecttree.h
    ../include/toonz/ttilesaver.h
    ../include/toonz/ttileset.h
    ../include/toonz/tvectorimageutils.h
    ../include/toonz/txshcell.h
    ../include/toonz/txshchildlevel.h
    ../include/toonz/txshcolumn.h
    ../include/toonz/txsheet.h
    ../include/toonz/txsheetexpr.h
    ../include/toonz/txshlevelcolumn.h
    ../include/toonz/txshleveltypes.h
    ../include/toonz/txshmeshcolumn.h
    ../include/toonz/txshnoteset.h
    ../include/toonz/txshpalettecolumn.h
    ../include/toonz/txshpalettelevel.h
    ../include/toonz/txshsoundlevel.h
    ../include/toonz/txshsoundtextcolumn.h
    ../include/toonz/txshsoundtextlevel.h
    ../include/toonz/txshzeraryfxcolumn.h
    ../include/toonz/txshzeraryfxlevel.h
    ../include/toonz/vectorizerparameters.h
    ../include/toutputproperties.h
    ../include/toonz/preferencesitemids.h
    ../include/toonz/txsheetcolumnchange.h
    ../include/toonz/expressionreferencemonitor.h
)

set(SOURCES
    autoadjust.cpp
    autoclose.cpp
    autopos.cpp
    captureparameters.cpp
	cellpositionratio.cpp
    childstack.cpp
    cleanupcolorstyles.cpp
    cleanuppalette.cpp
    cleanupparameters.cpp
    columnfan.cpp
    convert2tlv.cpp
    dpiscale.cpp
    fill.cpp
    fillutil.cpp
    fullcolorpalette.cpp
    fxdag.cpp
    glrasterpainter.cpp
    hook.cpp
    ikengine.cpp
    ikjacobian.cpp
    iknode.cpp
    ikskeleton.cpp
    imagebuilders.cpp
    imagelocation.cpp
    imagemanager.cpp
    imagepainter.cpp
    imagestyles.cpp
    levelproperties.cpp
    levelset.cpp
    levelupdater.cpp
    logger.cpp
    movierenderer.cpp
    multimediarenderer.cpp
    mypaintbrushstyle.cpp
    namebuilder.cpp
    Naa2TlvConverter.cpp
    observer.cpp
    onionskinmask.cpp
	orientation.cpp
    outputproperties.cpp
    preferences.cpp
    rasterbrush.cpp
    rasterstrokegenerator.cpp
    scenefx.cpp
    sceneproperties.cpp
    sceneresources.cpp
    scriptbinding.cpp
    scriptbinding_centerline_vectorizer.cpp
    scriptbinding_files.cpp
    scriptbinding_image.cpp
    scriptbinding_image_builder.cpp
    scriptbinding_level.cpp
    scriptbinding_outline_vectorizer.cpp
    scriptbinding_rasterizer.cpp
    scriptbinding_renderer.cpp
    scriptbinding_scene.cpp
    scriptbinding_toonz_raster_converter.cpp
    scriptengine.cpp
    skeleton.cpp
    skeletonlut.cpp
    stage.cpp
    stage2.cpp
    stageobjectutil.cpp
    stageplayer.cpp
    stagevisitor.cpp
    strokegenerator.cpp
    studiopalette.cpp
    stylemanager.cpp
    targetcolors.cpp
    tcamera.cpp
    tcenterlineadjustments.cpp
    tcenterlinecolors.cpp
    tcenterlinepolygonizer.cpp
    tcenterlineskeletonizer.cpp
    tcenterlinetostrokes.cpp
    tcenterlinevectorizer.cpp
    tcleanupper.cpp
    tcolumnfx.cpp
    tcolumnfxset.cpp
    tdistort.cpp
    texturemanager.cpp
    tlog.cpp
    tnewoutlinevectorize.cpp
    toonzfolders.cpp
    toonzimageutils.cpp
    toonzscene.cpp
    toutlinevectorizer.cpp
    tpinnedrangeset.cpp
    tproject.cpp
    trasterimageutils.cpp
    trastercentroid.cpp
    tstageobject.cpp
    tstageobjectspline.cpp
    tstageobjecttree.cpp
    ttilesaver.cpp
    ttileset.cpp
    tvectorimageutils.cpp
    txshcell.cpp
    txshchildlevel.cpp
    txshcolumn.cpp
    txsheet.cpp
    txsheetexpr.cpp
    txshlevel.cpp
    txshlevelcolumn.cpp
    txshnoteset.cpp
    txshpalettecolumn.cpp
    txshpalettelevel.cpp
    txshsimplelevel.cpp
    txshsoundcolumn.cpp
    txshsoundlevel.cpp
    txshsoundtextcolumn.cpp
    txshsoundtextlevel.cpp
    txshzeraryfxcolumn.cpp
    txshzeraryfxlevel.cpp
    xshhandlemanager.cpp
    vectorizerparameters.cpp
    sandor_fxs/blend.cpp
    sandor_fxs/BlurMatrix.cpp
    sandor_fxs/CIL.cpp
    sandor_fxs/CallCircle.cpp
    sandor_fxs/CallParam.cpp
    sandor_fxs/EraseContour.cpp
    sandor_fxs/InputParam.cpp
    sandor_fxs/Params.cpp
    sandor_fxs/Pattern.cpp
    sandor_fxs/PatternMapParam.cpp
    sandor_fxs/PatternPosition.cpp
    sandor_fxs/SDirection.cpp
    sandor_fxs/SError.cpp
    sandor_fxs/STColSelPic.cpp
    sandor_fxs/STPic.cpp
    sandor_fxs/YOMBInputParam.cpp
    sandor_fxs/YOMBParam.cpp
    sandor_fxs/calligraph.cpp
    sandor_fxs/patternmap.cpp
    sandor_fxs/toonz4_6staff.cpp
    tcolumnhandle.cpp
    tframehandle.cpp
    tfxhandle.cpp
    tobjecthandle.cpp
    tonionskinmaskhandle.cpp
    tpalettehandle.cpp
    tscenehandle.cpp
    txsheethandle.cpp
    txshlevelhandle.cpp
    doubleparamcmd.cpp
    fxcommand.cpp
    palettecmd.cpp
    palettecontroller.cpp
    studiopalettecmd.cpp
    tstageobjectcmd.cpp
    tbinarizer.cpp
    plasticdeformerfx.cpp
    txshmeshcolumn.cpp
    textureutils.cpp
    boardsettings.cpp
)

if(BUILD_TARGET_WIN)
    set(SOURCES ${SOURCES}
        avicodecrestrictions.cpp
    )
endif()

if(WITH_TRANSLATION)
    add_translation(toonzlib ${HEADERS} ${SOURCES})
endif()

qt5_wrap_cpp(SOURCES ${MOC_HEADERS})

add_library(toonzlib SHARED ${HEADERS} ${SOURCES})
if(BUILD_ENV_APPLE)
    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-install_name,@executable_path/libtoonzlib.dylib")
    add_dependencies(toonzlib tnzcore tnzbase tnzext)
endif()

add_definitions(
    -DTOONZLIB_EXPORTS
)

message("subdir: toonzlib")
message("Bin: " ${CMAKE_CURRENT_BINARY_DIR})

if(GLEW_FOUND)
    include_directories(${GLEW_INCLUDE_DIRS})
else()
    include_directories(${SDKROOT}/glew/glew-1.9.0/include)
endif()

include_directories(
    SYSTEM
    ${SDKROOT}/libusb/libusb-1.0.9/include
)
include_directories(
    ../toonzfarm/include
)

if(BUILD_ENV_MSVC)
    target_link_libraries(toonzlib
        Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Script Qt5::Multimedia
        ${GLUT_LIB} ${GL_LIB} ${MYPAINT_LIB_LDFLAGS} ${GLEW_LIB} vfw32.lib
        tnzcore tnzbase tnzext
    )
elseif(BUILD_ENV_APPLE)
    set(EXTRA_LIBS
        "$<TARGET_FILE:tnzcore>"
	    "$<TARGET_FILE:tnzbase>"
	    "$<TARGET_FILE:tnzext>"
        ${USB_LIB}
        ${MYPAINT_LIB_LDFLAGS}
    )

    target_link_libraries(toonzlib Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Script Qt5::Multimedia ${GLUT_LIB} ${GL_LIB} ${GLEW_LIB} ${EXTRA_LIBS})
elseif(BUILD_ENV_UNIXLIKE)
    _find_toonz_library(EXTRA_LIBS "tnzcore;tnzbase;tnzext")

    if(BUILD_TARGET_WIN)
        set(EXTRA_LIBS ${EXTRA_LIBS} -lvfw32)
    endif()

    target_link_libraries(toonzlib Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Script Qt5::Multimedia ${GLUT_LIB} ${GL_LIB} ${GLEW_LIB} ${EXTRA_LIBS} ${MYPAINT_LIB_LDFLAGS})
endif()
